"""
包含所有SQLAlchemy模型的基础类
"""
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy import Column, Integer, DateTime, func
from sqlalchemy.orm import DeclarativeBase


class Base(DeclarativeBase):
    """所有数据库模型的基类"""
    id = Column(Integer, primary_key=True, index=True)
    
    # 自动添加表名
    @declared_attr
    def __tablename__(cls) -> str:
        return cls.__name__.lower()


class TimestampMixin:
    """添加创建和更新时间戳的Mixin"""
    created_at = Column(DateTime, default=func.now(), nullable=False)
    updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), nullable=False)


# 从这里导入使用的模型，这样Alembic可以自动发现它们进行迁移
from app.models.user import User
from app.modules.gomoku.db.models.game import Game, GameMove 